package com.qf.question01.interceptor;


import com.qf.question01.entity.User;
import com.qf.question01.utils.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
@Slf4j
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

      log.debug("入参参数为",request,response,handler);

        HttpSession session = request.getSession();

        User attribute = (User) session.getAttribute(Constants.USER_LOGIN_SESSION_KEY);

        if (attribute!=null){

            return true;
        }

        response.sendRedirect("/login.html");

        return false;

    }
}
